#!/bin/bash

#
# 得到绝对路径, 仅做字符串的替换
# $1 需要转换的路径 $2 基础路径,默认工作目录
absPath(){
    local baseDir=$2
    local path=$1
    
    baseDir=${baseDir:-`pwd`}
    
    local parent=$(dirname $baseDir)
    if [[ "$path" =~ ^\/ ]]
    then
        echo $path
    elif [[ "$path" =~ ^\.\. ]]
    then
       echo $parent/${path##\.\.\/}
    elif [[ "$path" =~ ^\. ]]
    then
       echo $baseDir/${path##\.\/}
    else
       echo $baseDir/$path
    fi
      
}

# absPath ../a
# absPath ./a
# absPath a